package com.x.compute.common.constant;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.text.MessageFormat;

/**
 * 函数枚举
 * @author xuxin
 */

@Getter
@AllArgsConstructor
public enum FunctionEnum {
    ROUND("ROUND", "ROUND({0},{1})","四舍五入函数"),
    ROUNDUP("ROUNDUP", "ROUNDUP({0},{1})","向上舍入函数"),
    DATE_MONTH("DATEMONTH", "DATEMONTH({0},{1})","日期月份偏移函数"),
    IF("IF", "IF({0},{1},{2})", "判断函数");

    /**
     * 函数名称
     */
    public final String functionName;
    /**
     * 函数格式
     */
    public final String format;
    /**
     * 函数描述
     */
    public final String desc;

    /**
     * ROUND函数表达式转换
     * @param arg1
     * @param arg2
     * @return
     */
    public static String roundFormat(Object arg1, Object arg2){
        return MessageFormat.format(ROUND.format,arg1,arg2);
    }

    /**
     * ROUNDUP函数表达式转换
     * @param arg1
     * @param arg2
     * @return
     */
    public static String roundupFormat(Object arg1, Object arg2){
        return MessageFormat.format(ROUNDUP.format,arg1,arg2);
    }

    /**
     * DATEMONTH函数表达式转换
     * @param arg1
     * @param arg2
     * @return
     */
    public static String dateMonthFormat(Object arg1, Object arg2){
        return MessageFormat.format(DATE_MONTH.format,arg1,arg2);
    }

    /**
     * IF函数表达式转换
     * @param arg1
     * @param arg2
     * @param arg3
     * @return
     */
    public static String ifFormat(Object arg1, Object arg2, Object arg3){
        return MessageFormat.format(IF.format,arg1,arg2,arg3);
    }
}
